import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * User: Roman
 * Date: 06.09.12
 * Time: 16:25
 * To change this template use File | Settings | File Templates.
 */
public class Fast {

    private static Point[] points1;
    private static Point[] points2;

    private static void initializeGUI() {
        StdDraw.clear();
        StdDraw.setPenColor(StdDraw.BLUE);
        StdDraw.setXscale(0, 32768);
        StdDraw.setYscale(0, 32768);
    }

    private static void readPoints(String filename) {
        In in = new In(filename);
        Integer numberOfPoints = in.readInt();
        points1 = new Point[numberOfPoints];
        points2 = new Point[numberOfPoints];
        int counter = 0;
        while (counter < numberOfPoints) {
            points1[counter] = new Point(in.readInt(), in.readInt());
            points2[counter] = points1[counter];
            points2[counter++].draw();

        }
    }

    private static void printSequence(int startingPoint, int setPlaceInArray, int numberOfPointsInSet) {
        Arrays.sort(points2, setPlaceInArray, setPlaceInArray + numberOfPointsInSet);
        if (points1[startingPoint].compareTo(points2[setPlaceInArray]) < 0) {
            System.out.print(points1[startingPoint] + "->");
            for (int i = 0; i < numberOfPointsInSet; i++)
                if (i < numberOfPointsInSet - 1)
                    System.out.print(points2[setPlaceInArray + i] + "->");
                else
                    System.out.print(points2[setPlaceInArray + i]);
            System.out.println();
            points1[startingPoint].drawTo(points2[setPlaceInArray + numberOfPointsInSet - 1]);
            StdDraw.show(0);
        }
    }

    public static void main(String[] args) {
        String filename = args[0];
        initializeGUI();
        readPoints(filename);
        Arrays.sort(points1);
        Arrays.sort(points2);
        int counter;
        for (int i = 0; i < points1.length; i++) {
            Point pointToCheck = points1[i];
            Arrays.sort(points2, pointToCheck.SLOPE_ORDER);
            for (int j = 0; j < points2.length; j++) {
                double relativeSlopeToJ = pointToCheck.slopeTo(points2[j]);
                counter = 0;
                for (int k = j + 1; k < points2.length; k++) {
                    double relativeSlopeToK = pointToCheck.slopeTo(points2[k]);
                    if ((relativeSlopeToJ != relativeSlopeToK)) {
                        if (counter >= 2) {
                            printSequence(i, j, k - j + ((relativeSlopeToJ == relativeSlopeToK) ? 1 : 0));
                            j += counter;
                        }
                        counter = 0;
                        break;
                    } else
                        counter++;
                }
                if (counter >= 2) {
                    printSequence(i, j, points2.length - j);
                    j += counter;
                }
            }
        }

    }

}
